package net.vinote.smart.platform.service.handler;

import java.sql.SQLException;

import net.vinote.smart.platform.comm.PlatformConst;
import net.vinote.smart.platform.module.database.DBManager;
import net.vinote.smart.platform.module.database.DBManagerFactory;
import net.vinote.smart.platform.module.database.DBTransaction;
import net.vinote.smart.platform.module.database.bo.BizObject;
import net.vinote.smart.platform.service.dw.handler.CommonHandler;
import net.vinote.smart.platform.service.dw.handler.HandlerPerimissionAnnotation;
import net.vinote.smart.platform.service.util.Permission;
import net.vinote.smart.platform.service.util.Permission.PermissionEnum;

@HandlerPerimissionAnnotation(
		insert = @Permission(PermissionEnum.SMART_DW_LIBRARY_INSERT),
		update = @Permission(PermissionEnum.SMART_DW_LIBRARY_UPDATE),
		query = @Permission(PermissionEnum.SMART_DW_LIBRARY_QUERY),
		delete = @Permission(PermissionEnum.SMART_DW_LIBRARY_DELETE))
public class DataWindowLibraryHandler extends CommonHandler {
	@Override
	public void initDisplayForAdd(BizObject bo) {
		String doNo = request.getParameter("doNo");
		setDefaultValue("DONO", doNo);
		bo.setAttribute("ISVISIBLE", PlatformConst.YES);
		bo.setAttribute("ISREADONLY", PlatformConst.NO);
		bo.setAttribute("ISINUSE", PlatformConst.YES);
	}

	@Override
	public void initDisplayForEdit(BizObject bo) {
		setReadOnly("FIELDCODE", true);
	}

	@Override
	protected void beforeDelete(BizObject bo, DBTransaction tx)
			throws SQLException {
		DBManager bm = DBManagerFactory.getInstance("dataobject_event");
		tx.join(bm);
		bm.deleteWhereSql("doNo=? and fieldCode=?", bo.getAttribute("DONO"),
				bo.getAttribute("FIELDCODE"));
	}

}
